package cn.bdqn.controller;

import cn.bdqn.dao.EmploDaok;
import cn.bdqn.dao.IntegralDaok;
import cn.bdqn.dao.ProductDaok;
import cn.bdqn.pojo.Integral;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * @Author: 苏闻君
 * @Date: Created in 2020/7/30  14:58
 * 员工
 */
@Controller
public class EmploControllerk {

    @Autowired
    EmploDaok ep;
    @Autowired
    IntegralDaok idk;
    @Autowired
    ProductDaok pd;

    @ResponseBody
    @RequestMapping("/jifen")
    public Integer jifen(HttpServletRequest request){
        Integer id=Integer.parseInt(request.getParameter("userid"));
        Integer jifen=Integer.parseInt(request.getParameter("jifen"));
        Integer stock=Integer.parseInt(request.getParameter("kucun"));
        Integer proid=Integer.parseInt(request.getParameter("proid"));
        //查到用户的积分
        Integer chafen=idk.Selectjifen(id);
        if(chafen>=jifen){
            //扣除库存
            Integer res2=pd.updStock(stock,proid);
            String des="兑换商品扣除"+jifen+"积分";
            //插入积分表积分描述
            Integer res1=idk.insertjifen(id,des);
           Integer res= ep.updInteger(jifen,id);
            return 1;
        }
        return 0;
    }
}
